/*******************************************************************************
 *  myStorage.js, version 1.0.1
 *  (c) 2008 Sahid Ferdjaoui
 *
 *  myStorage.js is freely distributable under the terms of an LGPL v3 license.
 *  Project homepage : http://code.google.com/p/mystoragejs/
 *
 *******************************************************************************/

var myStorage = Class.create ({
	
  initialize: function () {
    this.Version = '1.0.1';
    this.h = new Hash ();
  },
	
  add: function (key, value, expire) {
    if (!expire)
      expire = 0;
    else expire += this.time ();
		
    if (this.get (key))
      return false;
		
    var atom = {'data':value, 'expire':expire};
    this.h.set (key, atom);
  },
	
  set: function (key, value, expire) {
    if (!expire)
      expire = 0;
    else expire += this.time ();
		
    var atom = {'data':value, 'expire':expire};
    this.h.set (key, atom);
  },
	
  get: function (key) {
    var atom = this.h.get (key);
    if (!atom)
      return false;
    if ((atom.expire > 0) && (atom.expire < this.time ()))  {
      this.del (key);
      return false;
    }
    return atom.data;
  },
	
  del: function (key) {
    this.h.unset (key);
  },
	
  time: function () {
    return Math.floor ((new Date()).getTime() / 1000);
  }
	
});
